from datetime import datetime
from importlib import reload

import app.portfolio_strategy
reload(app.portfolio_strategy)

from app.portfolio_strategy import BacktestingEngine
from trader.constant import Interval

import app.portfolio_strategy.strategies.pair_trading_strategy as stg
reload(stg)
from app.portfolio_strategy.strategies.pair_trading_strategy import PairTradingStrategy

engine = BacktestingEngine()
engine.set_parameters(
    vt_symbols=["IF2012.CFFEX", "au2012.SHFE"],
    interval=Interval.MINUTE,
    start=datetime(2010, 1, 1),
    end=datetime(2020, 12, 30),
    rates={
        "IF2012.CFFEX": 0/10000,
        "au2012.SHFE": 0/10000
    },
    slippages={
        "IF2012.CFFEX": 0,
        "au2012.SHFE": 0
    },
    sizes={
        "IF2012.CFFEX": 10,
        "au2012.SHFE": 10
    },
    priceticks={
        "IF2012.CFFEX": 1,
        "au2012.SHFE": 1
    },
    capital=1_000_000,
)

setting = {
    "boll_window": 20,
    "boll_dev": 1,
}
engine.add_strategy(PairTradingStrategy, setting)

engine.load_data()
engine.run_backtesting()
df = engine.calculate_result()
engine.calculate_statistics()
engine.show_chart()